package com.chen.webservice.controller;

import cn.hutool.core.collection.CollectionUtil;
import com.chen.base.http.WrapMapper;
import com.chen.base.http.Wrapper;
import com.chen.webservice.Utils.RuleConstants;
import com.chen.webservice.model.*;
import com.chen.webservice.service.ArrangeService;
import com.chen.webservice.service.ProgramCheckService;
import com.chen.webservice.service.ProgrammeBiz;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

@RestController
@Api(tags = "排单算法接口")
public class ProgrammeController {

    @Resource
    private ProgrammeBiz programmeBiz;
    @Resource
    private ArrangeService arrangeService;
    @Autowired
    private ProgramCheckService programCheckService;



//    @GetMapping("index")
    public String index(Model model){
        List<Programme> list = this.programmeBiz.getAllProgramme();
        System.out.println(list);
        model.addAttribute("msg","欢迎！");
        return list.toString();
    }

    @PostMapping("/program")
    @ApiOperation("排单算法")
    public Wrapper arrangeProgram(@Valid @RequestBody ConfigureParameterDTO dto) {
//        dto.setOrders(mockOrders(false));
        String errorMsg = checkParameterDTO(dto.getOrders(), dto.getOpenTime(), dto.getCloseTime(), dto.getFixOrders());
        if (StringUtils.isNotBlank(errorMsg)) {
            return WrapMapper.illegalArgument(errorMsg);
        }

        arrangeService.arrangeProgram(dto);
//        List<ProgramPlayOrderDTO> programPlayOrderDTOS = arrangeService.arrangeProgram(dto);
        return WrapMapper.ok(null);
    }

    /**
     * 排单算法参数校验
     *
     * @param orders
     * @param openTime
     * @param closeTime
     * @return
     */
    private String checkParameterDTO(List<Order> orders, Integer openTime, Integer closeTime, List<ConfigureParameterDTO.FixOrder> fixOrders) {
        // 校验参数，广告播放时长必须是15倍数
        if (!checkOrderPlayTime(orders)) {
            return "广告播放时长不正确";
        }
        // 开屏时间 > 关屏时间
        if (openTime > closeTime) {
            return "开屏时间大于关屏时间";
        }
        // order中必须有原创广告
        if (!checkHasOriginalOrder(orders)) {
            return "至少选择一条原创广告";
        }
        // 校验包屏时间是否重合
        if (checkCoverPlayTimeHasCovered(orders)) {
            return "包屏广告播放时间存在播放冲突!";
        }
        // 存在整点和半点播放的广告
        if (CollectionUtil.isNotEmpty(fixOrders)) {
            // 校验整点和半点播放的广告时长是否是15的倍数
            if (checkFixOrderPlayTime(fixOrders)) {
                return "整点和半点播放的广告时长不正确";
            }
            // 校验整点和半点广告是否与包屏广告播放时间冲突
            /*if (checkCoverWithFixOrderHasCovered(orders, fixOrders)) {
                return "包屏广告播放时间与整点和半点广告播放时间存在冲突!";
            }*/
        }

        return null;
    }

    /**
     * 包屏广告播放时间与整点和半点广告播放时间存在冲突
     * @param orders
     * @param fixOrders
     * @return
     */
    private boolean checkCoverWithFixOrderHasCovered(List<Order> orders, List<ConfigureParameterDTO.FixOrder> fixOrders) {
        List<Order> coverOrders = orders.stream().filter(x -> x.getPlayType() == 1).collect(Collectors.toList());
        for (Order coverOrder : coverOrders) {
            for (ConfigureParameterDTO.FixOrder fixOrder : fixOrders) {
                long fixEndTime = fixOrder.getStartTime() + fixOrder.getPlayTime();
                // 左侧不重叠
                boolean leftCoverFlag = coverOrder.getStartTime() < fixOrder.getStartTime() &&
                        coverOrder.getEndTime() < fixOrder.getStartTime();
                // 右侧不重叠
                boolean rightCoverFlag = coverOrder.getStartTime() > fixEndTime  && coverOrder.getEndTime() > fixEndTime;
                if (!(leftCoverFlag || rightCoverFlag)) {
                    // 存在包屏广告和整点/半点播放广告播放时间冲突
                    return true;
                }
            }
        }
        return false;
    }

    /**
     * 包屏广告播放时间存在播放冲突
     * @param orders
     * @return
     */
    private boolean checkCoverPlayTimeHasCovered(List<Order> orders) {
        List<Order> coverOrder = orders.stream().filter(x -> x.getPlayType() == 1).collect(Collectors.toList());
        for (int i = 0; i < coverOrder.size(); i++) {
            for (int j = i; j < coverOrder.size(); j++) {
                if (i == j) {
                    continue;
                }

                if (!(coverOrder.get(i).getEndTime() <= coverOrder.get(j).getStartTime() ||
                        coverOrder.get(i).getStartTime() >= coverOrder.get(j).getEndTime())) {
                    return true;
                }
            }
        }

        return false;
    }

//    @PostMapping("/rearrange")
    @ApiOperation("判断广告是否允许播放，重新排单")
    public Wrapper rearrange(@Valid @RequestBody RearrangeParameterDTO dto) {
//        dto.setOrders(mockOrders(false));
//        Order order111 = new Order("BSM-14F-制-HI魔都I心侬-60秒pin1231-v1-YS", 111L, 60, 0, 0, convertSec("0"), convertSec("0"),
//                RuleConstants.OrderType.ORIGIN.getValue(), RuleConstants.CateType.OTHERS.getValue(), RuleConstants.StyleType.WORD.getValue(),
//                RuleConstants.ColorType.BLACK.getValue(), RuleConstants.OrderRate.RATE_9.getValue(), RuleConstants.OrderAging.LONG_TERM.getValue());
//        dto.setNewOrder(order111);
        // 校验参数
        String errorMsg = checkParameterDTO(dto.getOrders(), dto.getOpenTime(), dto.getCloseTime(), null);
        if (StringUtils.isNotBlank(errorMsg)) {
            return WrapMapper.illegalArgument(errorMsg);
        }
        if (!checkOrderPlayTime(Collections.singletonList(dto.getNewOrder()))) {
            return WrapMapper.illegalArgument("广告播放时长不正确");
        }

        arrangeService.rearrangeProgram(dto);
        return WrapMapper.ok(null);
    }

    @PostMapping("/check/cover/program")
    @ApiOperation("校验包屏广告是否允许播放")
    public Wrapper<Boolean> checkCoverProgram(@Valid @RequestBody CheckCoverProgramCanPlayParameterDTO dto) {
        // 校验参数
        String errorMsg = checkParameterDTO(dto.getOrders(), dto.getOpenTime(), dto.getCloseTime(), null);
        if (StringUtils.isNotBlank(errorMsg)) {
            return WrapMapper.illegalArgument(errorMsg);
        }
        if (!checkOrderPlayTime(Collections.singletonList(dto.getNewOrder()))) {
            return WrapMapper.illegalArgument("广告播放时长不正确");
        }
        // 待校验广告必须是包屏广告
        if (!checkCoverOrderType(dto.getNewOrder())) {
            return WrapMapper.illegalArgument("待校验广告必须是包屏广告");
        }

        // 校验包屏广告是否允许播放
        Boolean canPlay = programCheckService.checkCoverProgram(dto);
        return WrapMapper.ok(canPlay);
    }

    /**
     * 待校验广告必须是包屏广告
     *
     * @param order
     * @return
     */
    private boolean checkCoverOrderType(Order order) {
        return order.getPlayType().equals(RuleConstants.PlayType.COVER.getValue());
    }

    @PostMapping("/check/other/program")
    @ApiOperation("校验其他广告是否允许播放")
    public Wrapper<Boolean> checkOtherProgram(@Valid @RequestBody CheckOtherProgramCanPlayParameterDTO dto) {
        // 校验参数
        for (CheckOtherProgramCanPlayParameterDTO.OneDayOrderData oneDayOrderData : dto.getOrderDataList()) {
            String errorMsg = checkParameterDTO(oneDayOrderData.getOrders(), oneDayOrderData.getOpenTime(), oneDayOrderData.getCloseTime(), null);
            if (StringUtils.isNotBlank(errorMsg)) {
                return WrapMapper.illegalArgument(errorMsg);
            }
        }
        if (!checkOrderPlayTime(Collections.singletonList(dto.getNewOrder()))) {
            return WrapMapper.illegalArgument("广告播放时长不正确");
        }
        // 待校验广告必须是其他类型广告
        if (!checkOtherProgramOrderType(dto.getNewOrder())) {
            return WrapMapper.illegalArgument("待校验广告必须是商业广告");
        }

        // 校验其他广告是否允许播放
        Boolean canPlay = programCheckService.checkOtherProgram(dto);
        return WrapMapper.ok(canPlay);
    }

    /**
     * 待校验广告必须是其他类型广告
     *
     * @param order
     * @return
     */
    private boolean checkOtherProgramOrderType(Order order) {
        return !(order.getPlayType().equals(RuleConstants.PlayType.COVER.getValue()) &&
                order.getCategory().equals(RuleConstants.OrderType.ORIGIN.getValue()));
    }

    /**
     * 校验order中必须有原创广告
     *
     * @param orders
     * @return
     */
    private boolean checkHasOriginalOrder(List<Order> orders) {
        for (Order order : orders) {
            if (order.getCategory() == RuleConstants.OrderType.ORIGIN.getValue()) {
                return true;
            }
        }
        return false;
    }

    /**
     * 校验整点和半点播放的广告时长是否是15的倍数
     * @param fixOrders
     * @return
     */
    private boolean checkFixOrderPlayTime(List<ConfigureParameterDTO.FixOrder> fixOrders) {
        for (ConfigureParameterDTO.FixOrder fixOrder : fixOrders) {
            if (fixOrder.getPlayTime() % 15 != 0) {
                return true;
            }
        }
        return false;
    }


    /**
     * 校验广告播放时长是否是15的整数倍
     *
     * @param orders
     * @return
     */
    private boolean checkOrderPlayTime(List<Order> orders) {
        for (Order order : orders) {
            if (order.getPlayTime() % 15 != 0) {
                return false;
            }
            if (order.getStartTime() > order.getEndTime()) {
                return false;
            }
        }
        return true;
    }

    /**
     * 模拟订单数据
     *
     * @param flag
     * @return
     */
    public static List<Order> mockOrders(boolean flag) {
        List<Order> orders = new ArrayList<>();

        Order order100 = new Order("BSM-21B-包屏-美孚1130-15秒", 100L, 3600, 1, 0, convertSec("20:00:00"), convertSec("21:00:00"),
                RuleConstants.OrderType.BUSINESS.getValue(), RuleConstants.CateType.SHIHUA.getValue(), RuleConstants.StyleType.WORD.getValue(),
                RuleConstants.ColorType.RED.getValue(), RuleConstants.OrderRate.RATE_7.getValue(), RuleConstants.OrderAging.LONG_TERM.getValue());
        Order order101 = new Order("BSM-20B-播-郎酒0413-15秒-YS", 101L, 15, 0, 60, convertSec("0"), convertSec("0"),
                RuleConstants.OrderType.BUSINESS.getValue(), RuleConstants.CateType.WINE.getValue(), RuleConstants.StyleType.COLOR.getValue(),
                RuleConstants.ColorType.BLUE.getValue(), RuleConstants.OrderRate.RATE_6.getValue(), RuleConstants.OrderAging.LONG_TERM.getValue());
        Order order102 = new Order("BSM-21-播-花旗银行换片0512-30秒-YS", 102L, 30, 0, 60, convertSec("0"), convertSec("0"),
                RuleConstants.OrderType.BUSINESS.getValue(), RuleConstants.CateType.BANK.getValue(), RuleConstants.StyleType.WORD.getValue(),
                RuleConstants.ColorType.BLUE.getValue(), RuleConstants.OrderRate.RATE_5.getValue(), RuleConstants.OrderAging.LONG_TERM.getValue());
        Order order103 = new Order("BSM-21B-播-卡尔蔡司1115-15秒-YS", 103L, 15, 0, 60, convertSec("0"), convertSec("0"),
                RuleConstants.OrderType.BUSINESS.getValue(), RuleConstants.CateType.GLASS.getValue(), RuleConstants.StyleType.WORD.getValue(),
                RuleConstants.ColorType.BLUE.getValue(), RuleConstants.OrderRate.RATE_6.getValue(), RuleConstants.OrderAging.LONG_TERM.getValue());
        Order order1040 = new Order("BSM-21B-插播-生日祝福1124-60s-ysl-v3-YS", 1040L, 60, 1, 0, convertSec("19:20:00"), convertSec("19:21:00"),
                RuleConstants.OrderType.BUSINESS.getValue(), RuleConstants.CateType.PERSON.getValue(), RuleConstants.StyleType.WORD.getValue(),
                RuleConstants.ColorType.PINK.getValue(), RuleConstants.OrderRate.RATE_5.getValue(), RuleConstants.OrderAging.LONG_TERM.getValue());
        Order order104 = new Order("BSM-21B-播-华宝基金1121-15秒-v5-gzx", 104L, 15, 0, 30, convertSec("0"), convertSec("0"),
                RuleConstants.OrderType.BUSINESS.getValue(), RuleConstants.CateType.BANK.getValue(), RuleConstants.StyleType.WORD.getValue(),
                RuleConstants.ColorType.BLUE.getValue(), RuleConstants.OrderRate.RATE_5.getValue(), RuleConstants.OrderAging.LONG_TERM.getValue());

        Order order105 = new Order("BSM-21A-播-UCCA展1111-15秒-YS", 105L, 15, 0, 60, convertSec("0"), convertSec("0"),
                RuleConstants.OrderType.GOVERNMENT.getValue(), RuleConstants.CateType.SHOW.getValue(), RuleConstants.StyleType.COLOR.getValue(),
                RuleConstants.ColorType.GREEN.getValue(), RuleConstants.OrderRate.RATE_8.getValue(), RuleConstants.OrderAging.LONG_TERM.getValue());
        Order order106 = new Order("BSM-21A-播-动感101东方风云榜1458期1111-30秒-dq-v1-YS", 106L, 15, 0, 10, convertSec("0"), convertSec("0"),
                RuleConstants.OrderType.GOVERNMENT.getValue(), RuleConstants.CateType.PROGRAMME.getValue(), RuleConstants.StyleType.WORD.getValue(),
                RuleConstants.ColorType.PURPLE.getValue(), RuleConstants.OrderRate.RATE_6.getValue(), RuleConstants.OrderAging.LONG_TERM.getValue());
        Order order107 = new Order("BSM-21C-播-野生救援王一博0721-30秒-YS", 107L, 30, 0, 30, convertSec("0"), convertSec("0"),
                RuleConstants.OrderType.GOVERNMENT.getValue(), RuleConstants.CateType.PUBLIC_WELFARE.getValue(), RuleConstants.StyleType.COMIC.getValue(),
                RuleConstants.ColorType.GREEN.getValue(), RuleConstants.OrderRate.RATE_5.getValue(), RuleConstants.OrderAging.LONG_TERM.getValue());
        Order order108 = new Order("BSM-21A-播-防疫口号1112-15s-ysl-v2-YS", 108L, 30, 0, 30, convertSec("0"), convertSec("0"),
                RuleConstants.OrderType.GOVERNMENT.getValue(), RuleConstants.CateType.PUBLIC_WELFARE.getValue(), RuleConstants.StyleType.COMIC.getValue(),
                RuleConstants.ColorType.BLUE.getValue(), RuleConstants.OrderRate.RATE_7.getValue(), RuleConstants.OrderAging.LONG_TERM.getValue());
        Order order109 = new Order("BSM-21A-播-上海广播《女心理师》1125-15秒-dq-v3", 109L, 300, 1, 0, convertSec("19:40:15"), convertSec("19:45:15"),
                RuleConstants.OrderType.GOVERNMENT.getValue(), RuleConstants.CateType.PROGRAMME.getValue(), RuleConstants.StyleType.COMIC.getValue(),
                RuleConstants.ColorType.PINK.getValue(), RuleConstants.OrderRate.RATE_6.getValue(), RuleConstants.OrderAging.LONG_TERM.getValue());
        Order order110 = new Order("BSM-21A-播-谦汇公务机1130-15s-gzx", 110L, 15, 0, 120, convertSec("0"), convertSec("0"),
                RuleConstants.OrderType.GOVERNMENT.getValue(), RuleConstants.CateType.PROGRAMME.getValue(), RuleConstants.StyleType.COMIC.getValue(),
                RuleConstants.ColorType.YELLOW.getValue(), RuleConstants.OrderRate.RATE_6.getValue(), RuleConstants.OrderAging.LONG_TERM.getValue());
        Order order1100 = new Order("BSM-21A-播-全国交通安全日1201-15秒-xqm-v1", 1100L, 15, 0, 30, convertSec("0"), convertSec("0"),
                RuleConstants.OrderType.GOVERNMENT.getValue(), RuleConstants.CateType.PROGRAMME.getValue(), RuleConstants.StyleType.COMIC.getValue(),
                RuleConstants.ColorType.BLUE.getValue(), RuleConstants.OrderRate.RATE_7.getValue(), RuleConstants.OrderAging.LONG_TERM.getValue());

//        Order order111 = new Order("BSM-14F-制-HI魔都I心侬-60秒pin1231-v1-YS", 111L, 60, 0, 0, convertSec("0"), convertSec("0"),
//                RuleConstants.OrderType.ORIGIN.getValue(), RuleConstants.CateType.OTHERS.getValue(), RuleConstants.StyleType.WORD.getValue(),
//                RuleConstants.ColorType.BLACK.getValue(), RuleConstants.OrderRate.RATE_9.getValue(), RuleConstants.OrderAging.LONG_TERM.getValue());
        Order order112 = new Order("BSM-18F-播-城市之窗片头-15s-YS", 112L, 15, 0, 0, convertSec("0"), convertSec("0"),
                RuleConstants.OrderType.ORIGIN.getValue(), RuleConstants.CateType.OTHERS.getValue(), RuleConstants.StyleType.SPECIAL_EFFICACY.getValue(),
                RuleConstants.ColorType.RED.getValue(), RuleConstants.OrderRate.RATE_8.getValue(), RuleConstants.OrderAging.LONG_TERM.getValue());
        Order order113 = new Order("BSM-21F-播-人民城市人民建1117-30s-gzx", 113L, 30, 0, 0, convertSec("0"), convertSec("0"),
                RuleConstants.OrderType.ORIGIN.getValue(), RuleConstants.CateType.OTHERS.getValue(), RuleConstants.StyleType.COLOR.getValue(),
                RuleConstants.ColorType.WHITE.getValue(), RuleConstants.OrderRate.RATE_6.getValue(), RuleConstants.OrderAging.LONG_TERM.getValue());
        Order order114 = new Order("BSM-20F-播-老上海0418-dq-v2-YS", 114L, 15, 0, 0, convertSec("0"), convertSec("0"),
                RuleConstants.OrderType.ORIGIN.getValue(), RuleConstants.CateType.OTHERS.getValue(), RuleConstants.StyleType.SPECIAL_EFFICACY.getValue(),
                RuleConstants.ColorType.BLUE.getValue(), RuleConstants.OrderRate.RATE_7.getValue(), RuleConstants.OrderAging.LONG_TERM.getValue());
        Order order115 = new Order("BSM-21F-播-城市之窗IP小智0929-45秒-YS", 115L, 45, 0, 0, convertSec("0"), convertSec("0"),
                RuleConstants.OrderType.ORIGIN.getValue(), RuleConstants.CateType.OTHERS.getValue(), RuleConstants.StyleType.SPECIAL_EFFICACY.getValue(),
                RuleConstants.ColorType.BLUE.getValue(), RuleConstants.OrderRate.RATE_7.getValue(), RuleConstants.OrderAging.LONG_TERM.getValue());
        Order order116 = new Order("BSM-21F-播-花历十二月腊梅1201-15s-gjh", 116L, 15, 0, 0, convertSec("0"), convertSec("0"),
                RuleConstants.OrderType.ORIGIN.getValue(), RuleConstants.CateType.OTHERS.getValue(), RuleConstants.StyleType.COMIC.getValue(),
                RuleConstants.ColorType.OTHERS.getValue(), RuleConstants.OrderRate.RATE_6.getValue(), RuleConstants.OrderAging.LONG_TERM.getValue());
        Order order117 = new Order("BSM-20F-播-十二月日历-1号-15s-lrh-YS", 117L, 15, 0, 0, convertSec("0"), convertSec("0"),
                RuleConstants.OrderType.ORIGIN.getValue(), RuleConstants.CateType.OTHERS.getValue(), RuleConstants.StyleType.COMIC.getValue(),
                RuleConstants.ColorType.YELLOW.getValue(), RuleConstants.OrderRate.RATE_5.getValue(), RuleConstants.OrderAging.LONG_TERM.getValue());
        Order order118 = new Order("BSM-21F-播-全新升级1130-30S-v3", 118L, 30, 0, 0, convertSec("0"), convertSec("0"),
                RuleConstants.OrderType.ORIGIN.getValue(), RuleConstants.CateType.OTHERS.getValue(), RuleConstants.StyleType.COMIC.getValue(),
                RuleConstants.ColorType.BLUE.getValue(), RuleConstants.OrderRate.RATE_7.getValue(), RuleConstants.OrderAging.LONG_TERM.getValue());
        Order order119 = new Order("BSM-21F-播-石砖联动1201-30秒", 119L, 30, 0, 0, convertSec("0"), convertSec("0"),
                RuleConstants.OrderType.ORIGIN.getValue(), RuleConstants.CateType.OTHERS.getValue(), RuleConstants.StyleType.SPECIAL_EFFICACY.getValue(),
                RuleConstants.ColorType.WHITE.getValue(), RuleConstants.OrderRate.RATE_6.getValue(), RuleConstants.OrderAging.LONG_TERM.getValue());
//        Order order1 = new Order("BSM-20B-包屏-德力西电器1118-60S-gzx-V4-YS",1L,3600,1,0,convertSec("19:00"),convertSec("20:00"),
//                OrderType.BUSINESS.getValue(), CateType.ELECT_EQUIPMENT.getValue(), StyleType.WORD.getValue(),
//                ColorType.RED.getValue(), OrderRate.RATE_4.getValue(), OrderAging.LONG_TERM.getValue());
//        Order order2 = new Order("BSM-20B-播-郎酒0413-15秒-YS",2L,15,0,60,convertSec("0"),convertSec("0"),
//                OrderType.BUSINESS.getValue(), CateType.WINE.getValue(), StyleType.COLOR.getValue(),
//                ColorType.RED.getValue(), OrderRate.RATE_6.getValue(), OrderAging.LONG_TERM.getValue());
//        Order order3 = new Order("BSM-21-播-花旗银行换片0512-30秒-YS",3L,30,0,40,convertSec("0"),convertSec("0"),
//                OrderType.BUSINESS.getValue(), CateType.BANK.getValue(), StyleType.WORD.getValue(),
//                ColorType.BLUE.getValue(), OrderRate.RATE_5.getValue(), OrderAging.LONG_TERM.getValue());
//        Order order4 = new Order("BSM-21B-播-携程-16s-ysl",4L,3600,1,0,convertSec("20:30"),convertSec("21:30"),
//                OrderType.BUSINESS.getValue(), CateType.TRIP.getValue(), StyleType.WORD.getValue(),
//                ColorType.WHITE.getValue(), OrderRate.RATE_6.getValue(), OrderAging.LONG_TERM.getValue());
//        Order order5 = new Order("BSM-21A-播-超级篮球赛0705-15S-YS",5L,15,0,30,convertSec("0"),convertSec("0"),
//                OrderType.BUSINESS.getValue(), CateType.GYM.getValue(), StyleType.COMIC.getValue(),
//                ColorType.RED.getValue(), OrderRate.RATE_5.getValue(), OrderAging.LONG_TERM.getValue());
//        Order order6 = new Order("BSM-21B-播-舍得酒0705-15s-dq-v5-YS",6L,15,0,120,convertSec("0"),convertSec("0"),
//                OrderType.BUSINESS.getValue(), CateType.WINE.getValue(), StyleType.COLOR.getValue(),
//                ColorType.RED.getValue(), OrderRate.RATE_7.getValue(), OrderAging.LONG_TERM.getValue());


//        Order order7 = new Order("BSM-21A-播-城市真英雄0705-15秒-xqm-YS",7L,15,0,60,convertSec("0"),convertSec("0"),
//                OrderType.GOVERNMENT.getValue(), CateType.PROGRAMME.getValue(), StyleType.WORD.getValue(),
//                ColorType.BLUE.getValue(), OrderRate.RATE_8.getValue(), OrderAging.LONG_TERM.getValue());
//        Order order8 = new Order("BSM-21A-播-动感101东方风云榜1440期0705-30秒-dq-v1-YS",8L,30,0,10,convertSec("0"),convertSec("0"),
//                OrderType.GOVERNMENT.getValue(), CateType.PROGRAMME.getValue(), StyleType.WORD.getValue(),
//                ColorType.PURPLE.getValue(), OrderRate.RATE_6.getValue(), OrderAging.LONG_TERM.getValue());
//        Order order9 = new Order("BSM-21C-播-野生救援王一博0721-30秒-YS",9L,30,0,30,convertSec("0"),convertSec("0"),
//                OrderType.GOVERNMENT.getValue(), CateType.PUBLIC_WELFARE.getValue(), StyleType.COMIC.getValue(),
//                ColorType.GREEN.getValue(), OrderRate.RATE_5.getValue(), OrderAging.LONG_TERM.getValue());
//        Order order10 = new Order("BSM-21A-播-上海旅游节0917-15秒-YS",10L,15,0,60,convertSec("0"),convertSec("0"),
//                OrderType.GOVERNMENT.getValue(), CateType.TRIP.getValue(), StyleType.COLOR.getValue(),
//                ColorType.BLUE.getValue(), OrderRate.RATE_7.getValue(), OrderAging.LONG_TERM.getValue());
//        Order order11 = new Order("BSM-21A-播-长江禁捕0902-15秒-v2-YS",11L,15,0,30,convertSec("0"),convertSec("0"),
//                OrderType.GOVERNMENT.getValue(), CateType.PUBLIC_WELFARE.getValue(), StyleType.WORD.getValue(),
//                ColorType.GREEN.getValue(), OrderRate.RATE_8.getValue(), OrderAging.LONG_TERM.getValue());
//        Order order12 = new Order("BSM-21F-播-神舟十二号0917-15S -dq-v3-YS",12L,300,1,0,convertSec("20:00"),convertSec("20:05"),
//                OrderType.GOVERNMENT.getValue(), CateType.CONFERENCE.getValue(), StyleType.COMIC.getValue(),
//                ColorType.BLUE.getValue(), OrderRate.RATE_9.getValue(), OrderAging.LONG_TERM.getValue());
//
//        Order order13 = new Order("BSM-14F-制-HI魔都I心侬-60秒pin1231-v1-YS",13L,60,0,0,convertSec("0"),convertSec("0"),
//                OrderType.ORIGIN.getValue(), CateType.OTHERS.getValue(), StyleType.WORD.getValue(),
//                ColorType.BLACK.getValue(), OrderRate.RATE_9.getValue(), OrderAging.LONG_TERM.getValue());
//        Order order14 = new Order("BSM-18A-播-我爱中国红底黄字1001-30秒-ysl-v2-YS",14L,30,0,0,convertSec("0"),convertSec("0"),
//                OrderType.ORIGIN.getValue(), CateType.OTHERS.getValue(), StyleType.COMIC.getValue(),
//                ColorType.BLACK.getValue(), OrderRate.RATE_9.getValue(), OrderAging.LONG_TERM.getValue());
//        Order order15 = new Order("BSM-18F-播-城市之窗过场B-10s-YS",15L,10,0,0,convertSec("0"),convertSec("0"),
//                OrderType.ORIGIN.getValue(), CateType.OTHERS.getValue(), StyleType.SPECIAL_EFFICACY.getValue(),
//                ColorType.RED.getValue(), OrderRate.RATE_8.getValue(), OrderAging.LONG_TERM.getValue());
//        Order order16 = new Order("BSM-19F-播-城市icon小动画0802-45秒-gzx-V2-YS",16L,45,0,0,convertSec("0"),convertSec("0"),
//                OrderType.ORIGIN.getValue(), CateType.OTHERS.getValue(), StyleType.COLOR.getValue(),
//                ColorType.WHITE.getValue(), OrderRate.RATE_6.getValue(), OrderAging.LONG_TERM.getValue());
//        Order order17 = new Order("BSM-20F-播-老上海0418-dq-v2-YS",17L,15,0,0,convertSec("0"),convertSec("0"),
//                OrderType.ORIGIN.getValue(), CateType.OTHERS.getValue(), StyleType.SPECIAL_EFFICACY.getValue(),
//                ColorType.GREEN.getValue(), OrderRate.RATE_7.getValue(), OrderAging.LONG_TERM.getValue());
//        Order order18 = new Order("BSM-21F-播-外滩的风0527-30s-gzx-V2-YS",18L,30,0,0,convertSec("0"),convertSec("0"),
//                OrderType.ORIGIN.getValue(), CateType.OTHERS.getValue(), StyleType.SPECIAL_EFFICACY.getValue(),
//                ColorType.PINK.getValue(), OrderRate.RATE_5.getValue(), OrderAging.LONG_TERM.getValue());
//        Order order19 = new Order("BSM-20F-播-HI外滩0803-30s-gzx-YS",19L,30,0,0,convertSec("0"),convertSec("0"),
//                OrderType.ORIGIN.getValue(), CateType.OTHERS.getValue(), StyleType.COMIC.getValue(),
//                ColorType.BLUE.getValue(), OrderRate.RATE_6.getValue(), OrderAging.LONG_TERM.getValue());
//        Order order20 = new Order("BSM-21F-九月日历-26号-15s-xqm-v1-YS",20L,15,0,0,convertSec("0"),convertSec("0"),
//                OrderType.ORIGIN.getValue(), CateType.OTHERS.getValue(), StyleType.COLOR.getValue(),
//                ColorType.OTHERS.getValue(), OrderRate.RATE_5.getValue(), OrderAging.LONG_TERM.getValue());
//        Order order21 = new Order("BSM-21F-秋老虎-30秒",21L,30,0,0,convertSec("0"),convertSec("0"),
//                OrderType.ORIGIN.getValue(), CateType.OTHERS.getValue(), StyleType.COMIC.getValue(),
//                ColorType.YELLOW.getValue(), OrderRate.RATE_7.getValue(), OrderAging.LONG_TERM.getValue());
//        Order order22 = new Order("九月花历桂花",22L,15,0,0,convertSec("0"),convertSec("0"),
//                OrderType.ORIGIN.getValue(), CateType.OTHERS.getValue(), StyleType.COMIC.getValue(),
//                ColorType.BLUE.getValue(), OrderRate.RATE_6.getValue(), OrderAging.LONG_TERM.getValue());
//
//        if(flag){
//            orders.add(order1);
//            orders.add(order2);
//            orders.add(order7);
//            orders.add(order17);
//            orders.add(order18);
//            return orders;
//        }
//
//            orders.add(order1);
//            orders.add(order2);
//            orders.add(order3);
//            orders.add(order4);
//            orders.add(order5);
//            orders.add(order6);
//            orders.add(order7);
//            orders.add(order8);
//            orders.add(order9);
//            orders.add(order10);
//            orders.add(order11);
//            orders.add(order12);
//            orders.add(order13);
//            orders.add(order14);
//            orders.add(order15);
//            orders.add(order16);
//            orders.add(order17);
//            orders.add(order18);
//            orders.add(order19);
//            orders.add(order20);
//            orders.add(order21);
//            orders.add(order22);

        orders.add(order100);
        orders.add(order101);
        orders.add(order102);
        orders.add(order103);
        orders.add(order104);
        orders.add(order1040);

        orders.add(order105);
        orders.add(order106);
        orders.add(order107);
        orders.add(order108);
        orders.add(order109);
        orders.add(order110);
        orders.add(order1100);

//        orders.add(order111);
        orders.add(order112);
        orders.add(order113);
        orders.add(order114);
        orders.add(order115);
        orders.add(order116);
        orders.add(order117);
        orders.add(order118);
        orders.add(order119);

        return orders;
    }

    public static int convertSec(String timeStr) {
        int time = 0;
        if (timeStr.matches("([01]?[0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]")) {
            String[] step = timeStr.split(":");
            time += Integer.parseInt(step[0]) * 60 * 60;
            time += Integer.parseInt(step[1]) * 60;
            time += Integer.parseInt(step[2]);
        }
        return time;
    }

}
